/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean;

import entity.Currency;
import java.math.BigDecimal;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Vojtisek
 */
@Stateless
public class CurrencyBean implements CurrencyLocal {

    @PersistenceContext
    private EntityManager em;
    private static final Logger logger = Logger.getLogger("CurrencyBean");

    public void create(String name, BigDecimal rate) throws Exception {
        Currency c = new Currency();
        c.setName(name);
        c.setRate(rate);
        em.persist(c);
        logger.log(Level.INFO, "Currency created: " + name + ",rate " + rate);
    }

    public Currency find(String name) throws Exception {
        return (Currency) em.createQuery("select o from Currency as o where o.name = :name").setParameter("name", name).getSingleResult();
    }
}
